package com.suxin.plugin.intergration.manager.loader;

import java.nio.file.Files;
import java.nio.file.Path;

/**
 * @author Tang
 * @classname JarPluginLoader
 * @description [  ]
 * @date 2022/7/3 23:04
 */
public class JarPluginLoader implements PluginLoader {

    @Override
    public boolean isApplicable(Path pluginPath) {
        return Files.exists(pluginPath) && pluginPath.getFileName().toString().toUpperCase().endsWith("JAR");
    }

    @Override
    public ClassLoader loadPlugin(Path pluginPath) {
        PluginClassLoader classLoader = new PluginClassLoader(getClass().getClassLoader());
        classLoader.addFile(pluginPath.toFile());
        return classLoader;
    }
}